home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / misc / vinced / include / examples / readprefs.c < prev    next >
C/C++ Source or Header  |  1999-04-19  |  9KB  |  220 lines

  1. /*****************************************************************
  2.  ** GetWindowPointer                                            **
  3.  ** Read the preferences of a ViNCEd window                     **
  4.  **-------------------------------------------------------------**
  5.  ** This program demonstrates how to read the preferences of    **
  6.  ** a ViNCEd window, just the stream.                           **
  7.  ** It also demonstrates how to use the link libraries.         **
  8.  **                                                             **
  9.  ** It is by no means complete, it doesn't print the flags and  **
  10.  ** the keyboard settings - this is just an example.            **
  11.  **                                                             **
  12.  ** For SAS/C, registerized parameters, long int, base relative **
  13.  ** addressing, you should link this with                       **
  14.  ** lib/vnc_stub.rr.base.lib                                    **
  15.  **                                                             **
  16.  ** You may also use the pragmas, but this means that you've to **
  17.  ** provide the console window pointer for each call, which is  **
  18.  ** rather annoying. Furthermore, it has to be passed in a5     **
  19.  ** which MIGHT cause trouble for some old or broken compilers  **
  20.  **                                                             **
  21.  ** Version 1.00 22 Aug 1998            © 1998 THOR-Software    **
  22.  ** Thomas Richter                                              **
  23.  *****************************************************************/
  24.  
  25. #include <exec/types.h>
  26. #include <exec/memory.h>
  27. #include <dos/dos.h>
  28. #include <dos/dosextens.h>
  29. #include <intuition/intuition.h>
  30.  
  31. #include <vnc/Window.h>
  32. #include <vnc/Prefs.h>
  33. #include <vnc/Macros.h>
  34.  
  35. /* We do not include proto/vnc.h since this would use the pragmas.
  36.    However, this program should demonstrate how to use the link
  37.    libraries. */
  38.  
  39. #include <clib/vnc_protos.h>
  40. #include <proto/exec.h>
  41. #include <proto/dos.h>
  42. #include <proto/graphics.h>
  43.  
  44. /* The library base is already defined in the link libraries */
  45. extern struct VNCBase *VNCBase;
  46.  
  47. /* Prototypes */
  48. int main(int argc,char **argv);
  49. void PrintPrefs(struct VNCPrefs *vpf);
  50. void PrintColor(struct ViColorEntry *vc);
  51. void PrintTAB(struct ViTabPriors *vt);
  52.  
  53. int main(int argc,char **argv)
  54. {
  55. struct ViNCWindow *cn;
  56. struct VNCPrefs *vpf;
  57.  
  58.         if (VNCBase=(struct VNCBase *)OpenLibrary("vnc.library",41L)) {
  59.                 /* Identify now the ViNCWindow of our stream */
  60.                 if (cn=FindCNWindow(Output())) {
  61.                         /* Set the window pointer to what we've read */
  62.                         SetCNWindow(cn);
  63.                         /* The next one is important: It releases the intuition
  64.                            window. Since we don't need it anyways, we're free
  65.                            to do it now. */
  66.                         UnFindCNWindow(Output());
  67.  
  68.  
  69.                         /* Allocate a buffer for the prefs */
  70.                         if (vpf=AllocPrefsBuffer()) {
  71.                                 /* Read the preferences from the window */
  72.                                 if (GetWindowPrefs_CN(vpf,-1)) {
  73.                                         /* Print them, just to demonstrate they are there */
  74.                                         PrintPrefs(vpf);
  75.                                 } else  Printf("Can't read the window prefs.\n");
  76.                                 FreePrefsBuffer(vpf);
  77.                         } else  Printf("No memory for the preferences buffer.\n");
  78.  
  79.  
  80.                 } else Printf("Output stream is not a ViNCEd window.\n");
  81.         } else Printf("Need vnc.library V41 (3.60) minimum.\n");
  82.  
  83.         return 0;
  84. }
  85.  
  86. /* Print the preferences, or at least the major part of it.
  87.    More could be done here, but this is mainly for demonstration
  88.    and not a complete program. */
  89.  
  90. void PrintPrefs(struct VNCPrefs *vpf)
  91. {
  92. struct List macrolist,buttonlist;
  93. struct ViNCMacro *vm;
  94. struct ViNCButton *vb;
  95. LONG fine;
  96. int i;
  97.  
  98.         /* First, convert the preferences into a somewhat more
  99.            useable form */
  100.         NewList(¯olist);
  101.         NewList(&buttonlist);
  102.  
  103.         LockWindow_CN();
  104.         fine=Prefs2List_CN(¯olist,&buttonlist,vpf,
  105.                         VPF_FUNCLENGTH,VPF_SHORTLENGTH,
  106.                         vpf->vpf_Macros,vpf->vpf_Buttons);
  107.         UnLockWindow_CN();
  108.  
  109.         if (!fine) {
  110.                 Printf("Can't build the macros and button list.\n");
  111.                 return;
  112.         }
  113.  
  114.  
  115. /* Now print the preferences, or at least a part of it. */
  116.  
  117.         Printf("Prefs version %ld.%ld.\n",vpf->vpf_Version,vpf->vpf_Revision);
  118.  
  119.         Printf("Size of the history     : %ld\n",vpf->vpf_HistorySize);
  120.         Printf("Number of strings       : %ld\n",vpf->vpf_Macros);
  121.         Printf("Maximal size of macros  : %ld\n",vpf->vpf_MacroSize);
  122.         Printf("Number of buttons       : %ld\n",vpf->vpf_Buttons);
  123.         Printf("Max. size of but. title : %ld\n",vpf->vpf_ButtonSize);
  124.         Printf("Size of the upper buffer: %ld\n",vpf->vpf_UpperLines);
  125.         Printf("Size of the lower buffer: %ld\n",vpf->vpf_LowerLines);
  126.         Printf("Size of the cache       : %ld\n",vpf->vpf_CacheLines);
  127.         Printf("Rebuild delay           : %ld ms\n",vpf->vpf_RebuildMicros/1000);
  128.         Printf("Scroll threshold        : %ld ms\n",vpf->vpf_SlowMicros/1000);
  129.         Printf("Blink speed             : %ld ms\n",vpf->vpf_BlinkMicros/1000);
  130.  
  131.         Printf("Default mode id         : 0x%08lx\n",vpf->vpf_DefModeID);
  132.         Printf("Path only qualifier     : 0x%04lx\n",vpf->vpf_PathOnlyQ);
  133.         Printf("Name only qualifier     : 0x%04lx\n",vpf->vpf_NameOnlyQ);
  134.  
  135.         /* Print the cursor color */
  136.         Printf("Cursor color            : ");
  137.         PrintColor(&(vpf->vpf_CursorColor));
  138.  
  139.         /* and the other color registers */
  140.         for (i=0;i<16;i++) {
  141.                 Printf("Color register %2ld       : ",i);
  142.                 PrintColor(&(vpf->vpf_Colors[i]));
  143.         }
  144.  
  145.         /* Print TAB expansion details */
  146.  
  147.         Printf("TAB expansion           :\n");
  148.         PrintTAB(&(vpf->vpf_TABPriors));
  149.  
  150.         Printf("Short expansion         :\n");
  151.         PrintTAB(&(vpf->vpf_SrtPriors));
  152.  
  153.         Printf("Devs expansion          :\n");
  154.         PrintTAB(&(vpf->vpf_DevPriors));
  155.  
  156.         Printf("Dir expansion           :\n");
  157.         PrintTAB(&(vpf->vpf_DirPriors));
  158.  
  159.         Printf("Icon expansion          :\n");
  160.         PrintTAB(&(vpf->vpf_InfPriors));
  161.  
  162.         Printf("Alternate expansion     :\n");
  163.         PrintTAB(&(vpf->vpf_AltPriors));
  164.  
  165.         Printf("TAB expansion           :\n");
  166.         PrintTAB(&(vpf->vpf_TABPriors));
  167.  
  168.         Printf("Requester Left Edge     :%ld\n",vpf->vpf_ReqLeft);
  169.         Printf("Requester Top Edge      :%ld\n",vpf->vpf_ReqTop);
  170.         Printf("Requester Width         :%ld\n",vpf->vpf_ReqWidth);
  171.         Printf("Requester Height        :%ld\n",vpf->vpf_ReqHeight);
  172.  
  173.         /* Print now the list of macros */
  174.         Printf("The macros              :\n");
  175.         for(vm=(struct ViNCMacro *)(macrolist.lh_Head);vm->vmac_succ;vm=vm->vmac_succ)
  176.                 Printf("%s\n",vm->vmac_text);
  177.  
  178.         /* And the list of buttons */
  179.         Printf("The buttons             :\n");
  180.         for(vb=(struct ViNCButton *)(buttonlist.lh_Head);vb->vbut_succ;vb=vb->vbut_succ)
  181.                 Printf("%s (%s)\n",vb->vbut_text,vb->vbut_title);
  182.  
  183.  
  184.         /* Now release both lists */
  185.         LockWindow_CN();
  186.         FreeMacroList_CN(¯olist);
  187.         FreeMacroList_CN(&buttonlist);
  188.         UnLockWindow_CN();
  189. }
  190.  
  191. /* Print a color register. We just print the RGB values, not
  192.    the flags. Extensions are left to the reader. */
  193.  
  194. void PrintColor(struct ViColorEntry *vc)
  195. {
  196.         Printf("Red 0x%04lx Green 0x%04lx Blue 0x%04lx\n",
  197.                 vc->vce_Red,vc->vce_Green,vc->vce_Blue);
  198. }
  199.  
  200. /* Print the priorities of the TAB expansion settings. Again,
  201.    the flags are not printed. */
  202.  
  203. void PrintTAB(struct ViTabPriors *vt)
  204. {
  205.         Printf("\tPath priority         : %ld\n",vt->vtp_PathPri);
  206.         Printf("\tCommand priority      : %ld\n",vt->vtp_CommandPri);
  207.         Printf("\tResident priority     : %ld\n",vt->vtp_ResidentPri);
  208.         Printf("\tIcon priority         : %ld\n",vt->vtp_InfoPri);
  209.  
  210.         Printf("\tDevice priority       : %ld\n",vt->vtp_DevicePri);
  211.         Printf("\tAssign priority       : %ld\n",vt->vtp_AssignPri);
  212.         Printf("\tVolume priority       : %ld\n",vt->vtp_VolumePri);
  213.         Printf("\tDirectory priority    : %ld\n",vt->vtp_DirPri);
  214.  
  215.         Printf("\tFile priority         : %ld\n",vt->vtp_FilePri);
  216.         Printf("\tExecutables priority  : %ld\n",vt->vtp_ExecPri);
  217.         Printf("\tScript priority       : %ld\n",vt->vtp_ScriptPri);
  218.  
  219. }
  220.